import json
import os
import time
import urllib.parse


def convert_time_to_timestamp(sec):
  timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(float(sec))) \
              if sec is not None else None
  return timestamp


def read_db_config(db_config_path):
  assert db_config_path and os.path.isfile(db_config_path), \
      'DB config file does not exist: %s' % db_config_path
  with open(db_config_path, 'r') as open_file:
    db_config = json.load(open_file)
    if 'password' in db_config:
      db_config['password'] = urllib.parse.quote_plus(db_config['password'])
  return db_config
